// 求三角形面积
function area(a : number, h : number) : number{
return 1 / 2 * a * h;
}
console.log(area(4, 5));//10
// 求两个数最大值   // 函数返回值类型默认为void(无类型)
function getMax(num1 : number, num2 : number) :number {
    return num1 > num2 ? num1 : num2;
}
console.log(getMax(5, 7));//7
// 使用interface创建接口，接口名称约定以I开头
interface IUser{
    name:string
    age:number
    sayHi:()=>void
}
let p1:IUser = {
    name:'andy',
    age:18,
    sayHi:()=>console.log(1111111111)
}
let p2:IUser = {
    name:'Me',
    age:20,
    sayHi:()=>console.log(2222222222)
}
console.log(p1.name);
p1.sayHi();
p2.sayHi()

// 类型断言
let d1 = document.querySelector('#d1') as HTMLDListElement;
d1.innerText = 'hello world';
d1.style.fontSize = '30px';
console.log(d1.style.fontSize);
// 操作样式，classlist属性
d1.classList.add('a','b','c');//添加类
d1.classList.remove('a');//移除类
let has = d1.classList.contains('b');//判断类名是否存在,返回布尔值
console.log(has);//true

// 事件
let btn1 = document.querySelector('#btn1') as HTMLButtonElement;
function handleClick(ev){
    let tar = ev.target as HTMLButtonElement;//ev.target,btn元素
    tar.style.fontSize = '20px';
    console.log('点我');   
}
btn1.addEventListener('click', handleClick, {once: true});//{once:true}只触发一次事件
let btn2 = document.querySelector('#btn2') as HTMLButtonElement;
btn2.addEventListener('click', function(){
    btn1.removeEventListener('click', handleClick)
})